//
//  JHMiddleWordViewController.m
//  JuniRengLish_iOS
//
//  Created by revogi on 2019/5/8.
//  Copyright © 2019 revogi. All rights reserved.
//

#import "JHMiddleWordViewController.h"
#import "JHMiddleWordTableViewCell.h"
#import "JHMiddleWordDownloadController.h"

//标志符
static NSString * const cellID = @"JHMiddleWordTableViewCell";

@interface JHMiddleWordViewController () <UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSArray *dataArray;
@property (nonatomic,strong) NSArray *listArray;

@end

@implementation JHMiddleWordViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"中考单词";
    self.dataArray = @[@"A-D",@"E-K",@"L-Q",@"R-T",@"U-Z"];
    self.listArray = [NSMutableArray array];
    [self initNav];
    [self initUI];
    if (iPhone5) {
        self.tableView.rowHeight=55;
    }else{
        self.tableView.rowHeight=70;
    }
    
    [self getWordsData];
}

- (void)getWordsData
{
    NSString *urlStr = [BaseUrl stringByAppendingString:book_GetBookList];
    [DJHttpTool postWithURL:urlStr params:@{@"parentid":@"7000"} success:^(id json) {
        self.listArray = [JHBookContDataModel mj_objectArrayWithKeyValuesArray:json[@"data"][0][@"data"]];
        MYLog(@"%lu", (unsigned long)self.listArray.count);
    } failure:^(NSError *error) {
        
    }];
}

- (void)initNav
{
    JHNavView *navView = [[JHNavView alloc]init];
    if (iPhone5) {
        navView.frame = CGRectMake(0, 0, JKScreenW, 125);
    }else{
        navView.frame = CGRectMake(0, 0, JKScreenW, 170);
    }
    navView.navTitle.text = @"中考单词";
    [self.view addSubview:navView];
}


#pragma mark  --隐藏导航栏

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}


- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}

-(void)initUI
{
   self.tableView=[[UITableView alloc]initWithFrame:CGRectMake(0,170,JKScreenW,JKScreenH) style:UITableViewStyleGrouped];
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    [self.tableView registerNib:[UINib nibWithNibName:@"JHMiddleWordTableViewCell" bundle:nil] forCellReuseIdentifier:cellID];
    self.tableView.scrollEnabled=NO;
    [self.view addSubview:self.tableView];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
   
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JHMiddleWordTableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    cell.typeLable.text=self.dataArray[indexPath.section];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    JHMiddleWordDownloadController *vc=[[JHMiddleWordDownloadController alloc]init];
    vc.dataModel = self.listArray[indexPath.section];
    [self.navigationController pushViewController:vc animated:YES];
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
